<?php

namespace app\api\controller\hezi;

use app\admin\model\HeziXcx;
use app\api\controller\Base;
use think\Request;

class Hezi extends Base
{

    public $appid;
    public $version;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->appid = $this->request->param('appid');
        $this->version = $this->request->param('version') ?: '0.0.0';
    }

    // 配置
    public function config()
    {
        $xcx = HeziXcx::get(['appid' => $this->appid]);

        $check = false;
        $ios_check = false;

        if ($xcx) {
            if ($this->version == $xcx->control_version) {
                $check = true;
            }
            $ios_check = $xcx->ios_check ? true : false;
        }

        $data = [
            'check' => $check,
            'ios_check' => $ios_check,
        ];

        $this->result('config', $data);
    }

    // 首页上部
    public function index()
    {
        $banner = HeziXcx::where('delstatus', 0)
            ->where('banner', '<>', '')
            ->where('banner', 'not null')
            ->whereNotLike('type', '%hezi%')
            ->order('width', 'desc')
            ->limit(4)
            ->select();

        for ($i = 0; $i < 3; $i++) {
            $data[] = HeziXcx::where('delstatus', 0)
                ->whereNotLike('type', '%hezi%')
                ->order('width', 'desc')
                ->limit($i * 10, 10)
                ->select();
        }
        foreach ($data as $list) {
            foreach ($list as $item) {
                if ($item->click_type == 3) {
                    $item->path = '/pages/index/index?appid=' . $item->appid;
                }
            }
        }

        $list = [
            "banner" => [
                "title" => "大图推荐",
                "icon" => "",
                "data" => $banner
            ],
            "category" => [
                [
                    "unit_id" => "adunit-c7f2f578b22f801f",
                ],
                [
                    "title" => "本月爆款",
                    "icon" => "http://gather.51weiwan.com/uploads/file/20180824/2fa8c980a2b55c6bc6cf9d51956b6de1.png",
                    "data" => $data[0]
                ],
                [
                    "title" => "主播推荐",
                    "icon" => "http://gather.51weiwan.com/uploads/file/20180824/3ed6938b09eea3b6ffe73830a243ba59.png",
                    "data" => $data[1]
                ],
                [
                    "title" => "抖音热玩",
                    "icon" => "http://gather.51weiwan.com/uploads/file/20180824/13325c96eb27acd2b295135555c9b926.png",
                    "data" => $data[2]
                ],
                [
                    "unit_id" => "adunit-9364084e6d0bdb21",
                ],
            ],
        ];
        $this->result('index', $list);
    }

    // 首页下部
    public function get_list()
    {
        $page = $this->request->param('page') ?: 1;
        $list = HeziXcx::where('delstatus', 0)
            ->whereNotLike('type', '%hezi%')
            ->order('width', 'asc')
            ->limit(($page - 1) * 7, 7)
            ->select();

        $data = [
            "icon" => "http://gather.51weiwan.com/uploads/app/20180824/bde8fb857c90f988bf2c796f33fbb4af.png",
            "title" => "游戏热榜",
            'list' => $list,
        ];
        $this->result('list', $data);
    }

    // 发现
    public function find()
    {
        $page = $this->request->param('page') ?: 1;
        $list = HeziXcx::where('delstatus', 0)
            ->where('banner', '<>', '')
            ->whereNotLike('type', '%hezi%')
            ->where('banner', 'not null')
            ->order('width', 'desc')
            ->limit(($page - 1) * 5, 5)
            ->select();
        $this->result('find', $list);
    }

    // 小盒子list
    public function xcx_list()
    {
        $list = HeziXcx::all(['belong' => $this->appid]);
        $main = HeziXcx::get(1);
        array_push($list, $main);
        $this->result('list', $list);
    }

    // 小程序详情
    public function xcx_detail($appid)
    {
        $xcx = HeziXcx::get(['appid' => $appid]);
        $this->result('xcx', $xcx);
    }

    // 审核假数据
    public function fake_info()
    {
        $rows = [
            [
                "ID" => 20,
                "Title" => "小汪与小兔",
                "Summary" => "我给你讲个笑话吧",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/20.gif",
                "Nex" => 25,
                "SortNum" => 0
            ],
            [
                "ID" => 19,
                "Title" => "背后踢不到人",
                "Summary" => "坑人不成反坑了自己啊",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/19.gif",
                "Nex" => 11,
                "SortNum" => 0
            ],
            [
                "ID" => 18,
                "Title" => "四小天鹅的内讧",
                "Summary" => "当，四小天鹅发生内讧······",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/18.gif",
                "Nex" => 3,
                "SortNum" => 0
            ],
            [
                "ID" => 17,
                "Title" => "二货用身体档冰雹",
                "Summary" => "当新车主遇上冰雹，你会看见这样的情况，势要用身体捍卫爱车。",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/17.gif",
                "Nex" => 6,
                "SortNum" => 0
            ],
            [
                "ID" => 16,
                "Title" => "我去怎么这么贵",
                "Summary" => "嗯，好吃好吃···虾米？这么贵···",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/16.gif",
                "Nex" => 2,
                "SortNum" => 0
            ],
            [
                "ID" => 15,
                "Title" => "熊猫看账单",
                "Summary" => "卧槽 又涨价了？",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/15.gif",
                "Nex" => 1,
                "SortNum" => 0
            ],
            [
                "ID" => 14,
                "Title" => "光影之剑",
                "Summary" => "是谁干的，看把运动员都弄朦啦。",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/14.gif",
                "Nex" => 2,
                "SortNum" => 0
            ],
            [
                "ID" => 13,
                "Title" => "烟雾站在头盔上",
                "Summary" => "坑爹呐",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/13.gif",
                "Nex" => 2,
                "SortNum" => 0
            ],
            [
                "ID" => 12,
                "Title" => "黏地的小狗",
                "Summary" => "看我佛山无影脚~·",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/12.gif",
                "Nex" => 2,
                "SortNum" => 0
            ],
            [
                "ID" => 11,
                "Title" => "狗狗不放开嘴",
                "Summary" => "打死都不放！！！",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/11.gif",
                "Nex" => 4,
                "SortNum" => 0
            ],
            [
                "ID" => 10,
                "Title" => "穿裙子坐摩托",
                "Summary" => "坐摩托穿裙子有多飘逸？",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/10.gif",
                "Nex" => 1,
                "SortNum" => 0
            ],
            [
                "ID" => 9,
                "Title" => "仓鼠用手梳头",
                "Summary" => "准备去约会了",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/9.gif",
                "Nex" => 1,
                "SortNum" => 0
            ],
            [
                "ID" => 8,
                "Title" => "愤怒的小鸟",
                "Summary" => "一屋不能容二鸟",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/8.gif",
                "Nex" => 2,
                "SortNum" => 0
            ],
            [
                "ID" => 7,
                "Title" => "捕鼠笼抓到猫咪",
                "Summary" => "尼玛 你不抓老鼠我忍了",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/7.gif",
                "Nex" => 2,
                "SortNum" => 0
            ],
            [
                "ID" => 6,
                "Title" => "老虎被小鸟吓倒",
                "Summary" => "老虎被小鸟吓倒",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/6.gif",
                "Nex" => 0,
                "SortNum" => 0
            ],
            [
                "ID" => 5,
                "Title" => "跳猫步",
                "Summary" => "表演跳猫步",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/5.gif",
                "Nex" => 0,
                "SortNum" => 0
            ],
            [
                "ID" => 4,
                "Title" => "趁没人多拿点纸巾回家给主人用",
                "Summary" => "趁现在没人，我赶紧多拿点纸巾回去给主人，",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/4.gif",
                "Nex" => 0,
                "SortNum" => 0
            ],
            [
                "ID" => 3,
                "Title" => "小短腿",
                "Summary" => "冲啊···大哥",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/3.gif",
                "Nex" => 1,
                "SortNum" => 0
            ],
            [
                "ID" => 2,
                "Title" => "打篮球鞋子掉了被丢一边",
                "Summary" => "尼玛 好一个缓兵之计 把鞋丢到观众台效果就更好了",
                "NewsIco" => "http://g.bnuni.com/upload/p/n/2019012314193888607154.gif",
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/2.gif",
                "Nex" => 15,
                "SortNum" => 0
            ],
            [
                "ID" => 1,
                "Title" => "被自己帅到的猴子",
                "Summary" => "猴儿，看镜子~哇塞，这是谁，好帅！！ ……",
                "NewsIco" => null,
                "NewsCover" => "http://g.bnuni.com/upload/p/wechat/news/maozhuayule/1.gif",
                "Nex" => 34,
                "SortNum" => 0
            ],
        ];
        $this->result('fake', $rows);
    }
    public function fake_game()
    {
        $game = [
            [
                'content' => "http://newgame.17173.com/content/01232019/094026811.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/frKksgbnbknbuvp.jpg!a-1-160x90.jpg',
                'title' => '《再战：孤舰绝境》评测7.5分当战舰海战遇见“吃鸡”',
                'desc' => '《再战：孤舰绝境》敢于用市场上略微小众的战舰题材结合“吃鸡”玩法展开，游戏本身的胆量就足以肯定，而游戏在玩法上与“吃鸡”玩法的结合度确实非常高，是一款值得一试的作品，哪怕没有成功“吃鸡”，你也能够享受一炮击沉敌人的快感。'
            ],
            [
                'content' => "http://newgame.17173.com/content/01142019/100003083.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/MXjsIpbmFzmicdi.jpg!a-1-160x90.jpg',
                'title' => '《超激斗梦境》评测8.2分拳拳到肉的无限流动作端游',
                'desc' => '在毒奶粉新鲜不在，而《失落的方舟》和《Project BBQ》等大作未进入国内市场的当下，网易放出这款类DNF的游戏是相当明智的一个选择，优秀的刷图体验和丰富而有趣的各种玩法则奠定了这款游戏的基石，虽然如今首测还面临着各种各样的BUG，但网易作为游戏大厂，玩家对游戏拥有足够的信心。'
            ],
            [
                'content' => "http://newgame.17173.com/content/01072019/095540940.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/UtHobobmCgleuFv.jpg!a-1-160x90.jpg',
                'title' => '《逍遥情缘》评测7.2分这个回合制也不错',
                'desc' => '《逍遥情缘》作为一款2D回合制网游，游戏保留了国产回合制独特的玩法节奏，同时围绕着回合制的核心玩点进行加强设计，为玩家提供了丰富的选择空间。'
            ],
            [
                'content' => "http://newgame.17173.com/content/12282018/110214601.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/bcIYUFbmCgsuswA.jpg!a-1-160x90.jpg',
                'title' => '《GRIS》评测8.5分 是游戏更是一项艺术',
                'desc' => '如今主打艺术、情感的独立游戏并不少，但能够像《GRIS》这样兼顾艺术与情感，且在两方面皆有不错表现的游戏并不多。它用淡雅清新的水彩画风吸引玩家的目光，又通过简单但不失韵味的内容引人入胜，整体音乐、音效等都能与游戏本身和玩家操作形成配合协调，最终呈现了一出令人流连忘返的奇妙之旅。'
            ],
            [
                'content' => "http://newgame.17173.com/content/12172018/101626777.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/MkxWsHbmFznFqah.jpg!a-1-160x90.jpg',
                'title' => '《梦想世界》评测7.5分传统回合制与创新的融合',
                'desc' => '《梦想世界》作为一款2D回合制网游，游戏在继承了回合制传统玩法的基础上，加入了一些独特的创新思路。从丰富的职业流派设计颠覆了回合制固有的战斗体验。多元的世界观则造就了游戏内容丰富的成长空间。'
            ],
            [
                'content' => "http://newgame.17173.com/content/12192018/104409187.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/iUQhabbmDsejspu.jpg!a-1-160x90.jpg',
                'title' => '《审判之眼：死神的遗言》评测8.5分 “如龙”宇宙的另一种可能性',
                'desc' => '如果玩家喜欢《如龙》系列，那《审判之眼》是绝对不容错过的；如果玩家想要在游戏中有推理、侦探的体验，那《审判之眼》恐怕在日本游戏中无出其右。况且，有木村拓哉的加持，更让不少“日剧粉”为之欢呼。总之，《审判之眼》值得一玩。'
            ],
            [
                'content' => "http://newgame.17173.com/content/12132018/112906800.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/iOBbsabmDEhspyA.jpg!a-1-160x90.jpg',
                'title' => '《旁观者2》评测8.5分     初看愿做旁观者，转眼已是局中人',
                'desc' => '毫无疑问，《旁观者2》是一款素质优异的独立游戏，在保持前作独到韵味的同时，各方面均不逊于前作。尽管游戏的重复游戏性因为系统设计而有所降低，但对于一款售价36元的小制作而言已是十足的可贵。'
            ],
            [
                'content' => "http://newgame.17173.com/content/12072018/154026145.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/bfDHjkbmChceehg.jpg!a-1-160x90.jpg',
                'title' => '《彩虹坠入》评测8.0分     光影交织的国产独立冒险',
                'desc' => '从《彩虹坠入》身上，能够看出NEXT STUDIO工作室对游戏的执着和热爱。《彩虹坠入》或许不能吸引所有人，也或许不会在商业上获得巨大的成功，但它无疑是国产游戏前进道路上扎实的一步。'
            ],
            [
                'content' => "http://newgame.17173.com/content/12062018/102943307.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/tKPjPMbmCguAphz.jpg!a-1-160x90.jpg',
                'title' => '一流剧本，二流表现，阔别六年的变与不变',
                'desc' => '《暗黑血统3》从发售到现在并没有收获很好的口碑，玩家的一部分隐性心理是非常好理解的：既然等待了六年，就应该来个更有冲击性的。但是同时需要理解的是：这六年并不是一个续作厚积薄发的六年，而是一个系列死而复生、从无到有的六年。'
            ],
            [
                'content' => "http://newgame.17173.com/content/12142018/141535957.shtml",
                'img' => 'http://i.17173cdn.com/0561y4/YWxqaGBf/gamebase/game-cover-square/ISrnYcbmCnrxFDn.jpg!a-1-160x90.jpg',
                'title' => '《任天堂明星大乱斗特别版》评测9.0分 史上最强大乱斗游戏',
                'desc' => '《任天堂明星大乱斗特别版》是一款任何一个喜欢动作游戏的玩家都不应该错过的精品。它的娱乐性很强，还易于上手；同时它的系统深度也够，也难于精通。最后，也相信玩家一定会享受到这款游戏所带来的快乐的！'
            ]
        ];
        $this->result('game', $game);
    }

}
